home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / pdevtest / RCS / server.c,v < prev   
Encoding:
Text File  |  1989-10-24  |  24.0 KB  |  968 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     89.10.24.12.37.50;  author brent;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     88.08.26.17.43.37;  author brent;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.08.26.16.23.53;  author brent;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     88.04.16.12.28.31;  author brent;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @Server code for pseudo-device benchmark
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @Updated to new C library, etc.
  38. @
  39. text
  40. @/* 
  41.  * server.c --
  42.  *
  43.  *    The server part of some multi-program synchronization primatives.
  44.  *    The routines here control N client programs.  This just means
  45.  *    telling them all to start, and hearing back from them when they're done.
  46.  *
  47.  * Copyright 1986 Regents of the University of California
  48.  * All rights reserved.
  49.  */
  50.  
  51. #ifndef lint
  52. static char rcsid[] = "$Header: /sprite/src/benchmarks/pdevtest/RCS/server.c,v 1.3 88/08/26 17:43:37 brent Exp Locker: brent $ SPRITE (Berkeley)";
  53. #endif not lint
  54.  
  55.  
  56. #include "sprite.h"
  57. #include "status.h"
  58. #include "errno.h"
  59. #include "fs.h"
  60. #include "dev/pdev.h"
  61. #include "stdio.h"
  62. #include "bit.h"
  63. #include "time.h"
  64. #include "sys.h"
  65. #include "sys/file.h"
  66.  
  67. char *pdev="./pdev";
  68.  
  69. extern Boolean writeBehind;
  70. extern int delay;
  71. extern int requestBufSize;
  72.  
  73. typedef int  (*IntProc)();
  74.  
  75. typedef struct ServerState {
  76.     int cntlStream;    /* Control stream to find out new clientStream's */
  77.     int numClients;
  78.     int *clientStream;    /* Array of client streams */
  79.     int maxStreamID;
  80.     Address *request;    /* Array of client request buffers */
  81.     char *clientState;    /* Array of client state words */
  82.     int *selectMaskPtr;
  83.     int selectMaskBytes;
  84.     IntProc opTable[7];    /* Operation switch table */
  85. } ServerState;
  86.  
  87. #define CLIENT_OPENED    0x1
  88. #define CLIENT_STARTED    0x2
  89. #define CLIENT_FINISHED    0x4
  90.  
  91. /*
  92.  * Need the select flag to know if we should block the client.
  93.  */
  94. extern Boolean selectP;
  95. Boolean blocked = FALSE;
  96.  
  97. /*
  98.  * Forward Declarations
  99.  */
  100. ReturnStatus NullProc();
  101. ReturnStatus ServeOpen();
  102. ReturnStatus ServeRead();
  103. ReturnStatus ServeWrite();
  104. ReturnStatus ServeIOControl();
  105. Pdev_Op ServeRequest();
  106.  
  107.  
  108. /*
  109.  *----------------------------------------------------------------------
  110.  *
  111.  * ServerSetup --
  112.  *
  113.  *    Establish contact with N clients.  A pseudo device is opened
  114.  *    and we are declared its "master", or "server".  After this
  115.  *    other processes can open the pseudo device and we'll get a private
  116.  *    stream back that we use for requests from that process.
  117.  *
  118.  * Results:
  119.  *    A pointer to state about the clients needed by ServerStart and
  120.  *    ServerWait.
  121.  *
  122.  * Side effects:
  123.  *    Opens the pseudo device as the server and waits for numClients
  124.  *    opens by client processes.
  125.  *    This exits (kills the process) upon error.
  126.  *
  127.  *----------------------------------------------------------------------
  128.  */
  129.  
  130. void
  131. ServerSetup(numClients, dataPtr)
  132.     int numClients;
  133.     ClientData *dataPtr;
  134. {
  135.     ServerState *statePtr;
  136.     int client;
  137.     int len;
  138.     int amountRead;
  139.     ReturnStatus status;
  140.     Pdev_Notify notify;
  141.     Pdev_SetBufArgs setBuf;
  142.     int streamID;
  143.     int maxStreamID;
  144.  
  145.     statePtr = (ServerState *)malloc(sizeof(ServerState));
  146.     statePtr->clientStream = (int *)malloc(numClients * sizeof(int));
  147.     statePtr->clientState = (char *)malloc(numClients);
  148.     statePtr->request = (Address *)malloc(numClients * sizeof(Address));
  149.     statePtr->numClients = numClients;
  150.  
  151.     statePtr->opTable[(int)PDEV_OPEN] = ServeOpen;
  152.     statePtr->opTable[(int)PDEV_CLOSE] = NullProc;
  153.     statePtr->opTable[(int)PDEV_READ] = ServeRead;
  154.     statePtr->opTable[(int)PDEV_WRITE] = ServeWrite;
  155.     statePtr->opTable[(int)PDEV_WRITE_ASYNC] = ServeWrite;
  156.     statePtr->opTable[(int)PDEV_IOCTL] = ServeIOControl;
  157.  
  158.     /*
  159.      * Open the pseudo device.
  160.      */
  161.     statePtr->cntlStream = open(pdev, O_RDONLY|O_CREAT|O_MASTER, 0666);
  162.     if (statePtr->cntlStream < 0) {
  163.     perror("Error opening pseudo device as master");
  164.     exit(errno);
  165.     }
  166.     maxStreamID = 0;
  167.     for (client=0 ; client<numClients ; client++) {
  168.     /*
  169.      * Read on our control stream (the one we just opened) messages
  170.      * that contain new streamIDs for the request-response streams
  171.      * back to the client process.
  172.      */
  173.     amountRead = read(statePtr->cntlStream, (Address)¬ify,
  174.                 sizeof(notify));
  175.     if (amountRead < 0) {
  176.         perror("Error reading control stream");
  177.         exit(status);
  178.     } else if (amountRead != sizeof(notify)) {
  179.         fprintf(stderr,
  180.         "Warning, short read (%d) on control stream\n", amountRead);
  181.     }
  182.     streamID = notify.newStreamID;
  183.     if (streamID > statePtr->maxStreamID) {
  184.         statePtr->maxStreamID = streamID;
  185.     }
  186.     /*
  187.      * Tell the kernel where the request buffer is.
  188.      */
  189.     requestBufSize += sizeof(Pdev_Request);
  190.     statePtr->request[client] = malloc(requestBufSize);
  191.     setBuf.requestBufAddr = statePtr->request[client];
  192.     setBuf.requestBufSize = requestBufSize;
  193.     setBuf.readBufAddr = (Address)NULL;
  194.     setBuf.readBufSize = 0;
  195.     Fs_IOControl(streamID, IOC_PDEV_SET_BUF,
  196.             sizeof(Pdev_SetBufArgs), (Address)&setBuf, 0, NULL);
  197.     /*
  198.      * Set(Unset) write-behind by the client.
  199.      */
  200.     Fs_IOControl(streamID, IOC_PDEV_WRITE_BEHIND,
  201.             sizeof(int), (Address)&writeBehind, 0, NULL);
  202.     statePtr->clientStream[client] = streamID;
  203.     statePtr->clientState[client] = CLIENT_OPENED;
  204.     fprintf(stderr, "Got client on stream %d\n",streamID);
  205.     ServeRequest(statePtr->clientStream[client],
  206.              statePtr->request[client],
  207.              statePtr->opTable);
  208.     }
  209.     /*
  210.      * Now that we know the largest stream ID used for a client stream
  211.      * we can allocate and initialize the select mask for the streams.
  212.      */
  213.     statePtr->selectMaskBytes = Bit_NumBytes(statePtr->maxStreamID);
  214.     statePtr->selectMaskPtr = (int *)malloc(statePtr->selectMaskBytes);
  215.     bzero((Address)statePtr->selectMaskPtr, statePtr->selectMaskBytes);
  216.     for (client=0 ; client < numClients ; client++) {
  217.     Bit_Set(statePtr->clientStream[client], statePtr->selectMaskPtr);
  218.     }
  219.     *dataPtr = (ClientData)statePtr;
  220. }
  221.  
  222. /*
  223.  *----------------------------------------------------------------------
  224.  *
  225.  * ServeRequest --
  226.  *
  227.  *    The top level service routine that reads client requests
  228.  *    and branches out to a handler for the request.  This takes
  229.  *    care of error conditions and allocating space for the
  230.  *    request and the reply parameters.
  231.  *
  232.  * Results:
  233.  *    None
  234.  *
  235.  * Side effects:
  236.  *    The server side of the pseudo-device protocol.
  237.  *
  238.  *----------------------------------------------------------------------
  239.  */
  240.  
  241. Pdev_Op
  242. ServeRequest(clientStreamID, myRequestBuf, opTable)
  243.     int clientStreamID;
  244.     Address myRequestBuf;
  245.     IntProc *opTable;
  246. {
  247.     static char *replyBuf = (char *)NULL;
  248.     static int replyBufSize = 0;
  249.     static Pdev_BufPtrs lastBufPtrs;
  250.     Pdev_BufPtrs bufPtrs;
  251.     Pdev_Reply reply;
  252.     register ReturnStatus status;
  253.     register Pdev_Request *requestPtr;
  254.     register Pdev_Op operation;
  255.     int numBytes;
  256.     register char *requestData;
  257.     register Address requestBuf;
  258.     register int i;
  259.  
  260.     /*
  261.      * Read the current pointers for the request buffer.
  262.      */
  263.  
  264.     numBytes = read(clientStreamID, (Address) &bufPtrs, sizeof(Pdev_BufPtrs));
  265.     if (numBytes < 0) {
  266.     } else if (numBytes != sizeof(Pdev_BufPtrs)) {
  267.     panic("ServeRequest: short read %d != sizeof(Pdev_BufPtrs)\n",numBytes);
  268.     }
  269.     if (bufPtrs.magic != PDEV_BUF_PTR_MAGIC) {
  270.     fprintf(stderr, "ServeRequest: bad ptr magic <%x>\n",
  271.         bufPtrs.magic);
  272.     fprintf(stderr, "\tprevPtrs <%d,%d> currentPtrs <%d,%d>\n",
  273.         lastBufPtrs.requestFirstByte, lastBufPtrs.requestLastByte,
  274.         bufPtrs.requestFirstByte, bufPtrs.requestLastByte);
  275.     panic("panic");
  276.     }
  277.     /*
  278.      * While there are still requests in the buffer, service them.
  279.      */
  280.     requestBuf = bufPtrs.requestAddr;
  281.     while (bufPtrs.requestFirstByte < bufPtrs.requestLastByte) {
  282.     requestPtr = (Pdev_Request *)&requestBuf[bufPtrs.requestFirstByte];
  283.     if (requestPtr->hdr.magic != PDEV_REQUEST_MAGIC) {
  284.         fprintf(stderr, "ServeRequest, bad request magic <%x>\n",
  285.                 requestPtr->hdr.magic);
  286.         fprintf(stderr, "\tprevPtrs <%d,%d> currentPtrs <%d,%d>\n",
  287.         lastBufPtrs.requestFirstByte, lastBufPtrs.requestLastByte,
  288.         bufPtrs.requestFirstByte, bufPtrs.requestLastByte);
  289.         panic("panic");
  290.     }
  291.     requestData = (Address)((int)requestPtr + sizeof(Pdev_Request));
  292.  
  293.     if (replyBuf == (char *)NULL) {
  294.         replyBuf = (char *)malloc(requestPtr->hdr.replySize);
  295.         replyBufSize = requestPtr->hdr.replySize;
  296.     } else if (replyBufSize < requestPtr->hdr.replySize) {
  297.         free((char *)replyBuf);
  298.         replyBuf = (char *)malloc(requestPtr->hdr.replySize);
  299.         replyBufSize = requestPtr->hdr.replySize;
  300.     }
  301.     /*
  302.      * Switch out the to the handler for the pdev operation.
  303.      */
  304.     operation = requestPtr->hdr.operation;
  305.     status = (*opTable[(int)operation])(clientStreamID,
  306.         requestPtr, requestData, replyBuf, &reply.selectBits);
  307.  
  308.     if (delay > 0) {
  309.         for (i=delay<<1 ; i>0 ; i--) ;
  310.     }
  311.  
  312.     if (operation != PDEV_WRITE_ASYNC) {
  313.         /*
  314.          * Set up the reply and tell the kernel about it.
  315.          */
  316.     
  317.         reply.magic = PDEV_REPLY_MAGIC;
  318.         reply.status = SUCCESS;
  319.         reply.replySize = requestPtr->hdr.replySize;
  320.         reply.replyBuf = replyBuf;
  321.         reply.signal = 0;
  322.         reply.code = 0;
  323.         status = Fs_IOControl(clientStreamID, IOC_PDEV_REPLY,
  324.                     sizeof(Pdev_Reply),
  325.                     (Address) &reply, 0, NULL);
  326.         if (status != SUCCESS) {
  327.         panic("%s; status \"%s\"",
  328.             "ServeRequest couldn't send reply",
  329.             Stat_GetMsg(status));
  330.         }
  331.     }
  332.     bufPtrs.requestFirstByte += requestPtr->hdr.messageSize;
  333.     }
  334.     Fs_IOControl(clientStreamID, IOC_PDEV_SET_PTRS,
  335.             sizeof(Pdev_BufPtrs), (Address)&bufPtrs,
  336.             0, NULL);
  337.     return(operation);
  338. }
  339.  
  340. /*
  341.  *----------------------------------------------------------------------
  342.  *
  343.  * Serve --
  344.  *
  345.  *    Listen for requests from client's, returning after all clients
  346.  *    have closed their streams.
  347.  *
  348.  * Results:
  349.  *    None
  350.  *
  351.  * Side effects:
  352.  *    Handle all requests by clients.
  353.  *
  354.  *----------------------------------------------------------------------
  355.  */
  356.  
  357. void
  358. Serve(data)
  359.     ClientData data;
  360. {
  361.     ServerState *statePtr;
  362.     int client;
  363.     ReturnStatus status;
  364.     int *selectMaskPtr;
  365.     int numFinishedClients;
  366.     int numReady;
  367.     Pdev_Op operation;
  368.  
  369.     statePtr = (ServerState *)data;
  370.     selectMaskPtr = (int *)malloc(statePtr->selectMaskBytes);
  371.     numFinishedClients = 0;
  372.     do {
  373.     bcopy((Address)statePtr->selectMaskPtr, (Address)selectMaskPtr,
  374.         statePtr->selectMaskBytes);
  375.     status = Fs_Select(statePtr->maxStreamID, NULL, selectMaskPtr,
  376.                 NULL, NULL, &numReady);
  377.     for (client=0 ; client < statePtr->numClients ; client++) {
  378.         /*
  379.          * Look for the each client's bit in the select mask and read the
  380.          * corresponding stream for its initial request.
  381.          */
  382.         if (Bit_IsSet(statePtr->clientStream[client], selectMaskPtr)) {
  383.         /*
  384.          * Handle the client's request.  If it's a close
  385.          * then clear the client's bit from the select mask so
  386.          * don't bother checking it again.
  387.          */
  388.         operation = ServeRequest(statePtr->clientStream[client],
  389.                  statePtr->request[client],
  390.                  statePtr->opTable);
  391.         if (operation == PDEV_CLOSE ||
  392.             operation == (Pdev_Op)-1) {
  393.             fprintf(stderr, "Client %d %s...", client,
  394.             (operation == PDEV_CLOSE) ? "closed" : "error" );
  395.             numFinishedClients++;
  396.             statePtr->clientState[client] |= CLIENT_FINISHED;
  397.             Bit_Clear(statePtr->clientStream[client],
  398.                 statePtr->selectMaskPtr);
  399.         } else if ((operation == PDEV_READ) && selectP) {
  400.             /*
  401.              * If the select flag is set, then we must
  402.              * remember to simulate input for the client
  403.              * every so often.  This tests regular blocking
  404.              * reads, and selects by the client.  This goes
  405.              * with the fact that we only return FS_WRITABLE
  406.              * if the select flag is set.
  407.              */
  408.             Time time;
  409.             int selectBits;
  410.             time.seconds = 0;
  411.             time.microseconds = 400;
  412.             Sync_WaitTime(time);
  413.             printf("Waking up client\n");
  414.             selectBits = FS_READABLE|FS_WRITABLE;
  415.             Fs_IOControl(statePtr->clientStream[client],
  416.                 IOC_PDEV_READY, sizeof(int), &selectBits,
  417.                 0, NULL);
  418.         }
  419.         }
  420.     }
  421.     } while (numFinishedClients < statePtr->numClients);
  422.     fprintf(stderr, "\n");
  423. }
  424.  
  425. /*
  426.  *----------------------------------------------------------------------
  427.  *
  428.  * ServeOne --
  429.  *
  430.  *    A service loop for one client.  More bare-bones test used
  431.  *    for timing.
  432.  *
  433.  * Results:
  434.  *    None
  435.  *
  436.  * Side effects:
  437.  *    Handle all requests one client.
  438.  *
  439.  *----------------------------------------------------------------------
  440.  */
  441.  
  442. void
  443. ServeOne(data)
  444.     ClientData data;
  445. {
  446.     register ServerState *statePtr;
  447.     register int client;
  448.     ReturnStatus status;
  449.     int *selectMaskPtr;
  450.     int numFinishedClients;
  451.     int numReady;
  452.     Pdev_Op operation;
  453.  
  454.     statePtr = (ServerState *)data;
  455.     client = 0;
  456.     do {
  457.     operation = ServeRequest(statePtr->clientStream[client],
  458.              statePtr->request[client],
  459.              statePtr->opTable);
  460.     if (operation == PDEV_CLOSE ||
  461.         operation == (Pdev_Op)-1) {
  462.         fprintf(stderr, "Client %d %s...", client,
  463.         (operation == PDEV_CLOSE) ? "closed" : "error" );
  464.         break;
  465.     } else if ((operation == PDEV_READ) && selectP) {
  466.         /*
  467.          * If the select flag is set, then we must
  468.          * remember to simulate input for the client
  469.          * every so often.  This tests regular blocking
  470.          * reads, and selects by the client.  This goes
  471.          * with the fact that we only return FS_WRITABLE
  472.          * if the select flag is set.
  473.          */
  474.         Time time;
  475.         int selectBits;
  476.         time.seconds = 0;
  477.         time.microseconds = 400;
  478.         Sync_WaitTime(time);
  479.         printf("Waking up client\n");
  480.         selectBits = FS_READABLE|FS_WRITABLE;
  481.         Fs_IOControl(statePtr->clientStream[client],
  482.             IOC_PDEV_READY, sizeof(int), &selectBits,
  483.             0, NULL);
  484.     }
  485.     } while (1);
  486.     fprintf(stderr, "\n");
  487. }
  488.  
  489. /*
  490.  *----------------------------------------------------------------------
  491.  *
  492.  * NullProc --
  493.  *
  494.  *    The do-nothing service procedure.
  495.  *
  496.  * Results:
  497.  *    SUCCESS
  498.  *
  499.  * Side effects:
  500.  *    Zeroes out the reply buffer.
  501.  *
  502.  *----------------------------------------------------------------------
  503.  */
  504.  
  505. ReturnStatus
  506. NullProc(streamID, requestPtr, requestBuf, replyBuf, selectBitsPtr)
  507.     int streamID;
  508.     Pdev_Request *requestPtr;
  509.     Address requestBuf;
  510.     Address replyBuf;
  511.     int *selectBitsPtr;
  512. {
  513.     if (requestPtr->hdr.replySize > 0) {
  514.     bzero(replyBuf, requestPtr->hdr.replySize);
  515.     }
  516.     return(SUCCESS);
  517. }
  518.  
  519. /*
  520.  *----------------------------------------------------------------------
  521.  *
  522.  * ServeOpen --
  523.  *
  524.  *    React to an Open request.  This initializes the
  525.  *    select state to both readable and writable.
  526.  *
  527.  * Results:
  528.  *    SUCCESS
  529.  *
  530.  * Side effects:
  531.  *    Print statement.
  532.  *
  533.  *----------------------------------------------------------------------
  534.  */
  535.  
  536. ReturnStatus
  537. ServeOpen(streamID, requestPtr, requestBuf, replyBuf, selectBitsPtr)
  538.     int streamID;
  539.     Pdev_Request *requestPtr;
  540.     Address requestBuf;
  541.     Address replyBuf;
  542.     int *selectBitsPtr;
  543. {
  544.     fprintf(stderr, "Open request, streamID %d\n", streamID);
  545.     *selectBitsPtr = FS_READABLE | FS_WRITABLE;
  546.     return(SUCCESS);
  547. }
  548.  
  549. /*
  550.  *----------------------------------------------------------------------
  551.  *
  552.  * ServeRead --
  553.  *
  554.  *    Return data for a read request.  This plays a game with the
  555.  *    client if the select flag (-s) is set:  every other read
  556.  *    gets blocked in order to test IOC_PDEV_READY.
  557.  *
  558.  * Results:
  559.  *    SUCCESS
  560.  *
  561.  * Side effects:
  562.  *    Zeroes out the reply buffer.
  563.  *
  564.  *----------------------------------------------------------------------
  565.  */
  566.  
  567. ReturnStatus
  568. ServeRead(streamID, requestPtr, requestBuf, replyBuf, selectBitsPtr)
  569.     int streamID;
  570.     Pdev_Request *requestPtr;
  571.     Address requestBuf;
  572.     Address replyBuf;
  573.     int *selectBitsPtr;
  574. {
  575.     if (selectP && !blocked) {
  576.     blocked = TRUE;
  577.     *selectBitsPtr = FS_WRITABLE;
  578.     return(FS_WOULD_BLOCK);
  579.     } else {
  580.     if (requestPtr->hdr.replySize > 0) {
  581.         bzero(replyBuf, requestPtr->hdr.replySize);
  582.         replyBuf[0] = 'z';
  583.     }
  584.     blocked = FALSE;
  585.     if (! selectP) {
  586.         *selectBitsPtr = FS_WRITABLE | FS_READABLE;
  587.     } else {
  588.         *selectBitsPtr = FS_WRITABLE;
  589.     }
  590.     return(SUCCESS);
  591.     }
  592. }
  593.  
  594. /*
  595.  *----------------------------------------------------------------------
  596.  *
  597.  * ServeWrite --
  598.  *
  599.  *    Handle a write request.
  600.  *
  601.  * Results:
  602.  *    SUCCESS
  603.  *
  604.  * Side effects:
  605.  *    Sets up the select bits.
  606.  *
  607.  *----------------------------------------------------------------------
  608.  */
  609.  
  610. ReturnStatus
  611. ServeWrite(streamID, requestPtr, requestBuf, replyBuf, selectBitsPtr)
  612.     int streamID;
  613.     Pdev_Request *requestPtr;
  614.     Address requestBuf;
  615.     Address replyBuf;
  616.     int *selectBitsPtr;
  617. {
  618.     *selectBitsPtr = FS_WRITABLE;
  619.     if (! selectP) {
  620.     *selectBitsPtr |= FS_READABLE;
  621.     }
  622.     requestPtr->hdr.replySize = sizeof(int);
  623.     *(int *)replyBuf = requestPtr->hdr.requestSize;    /* amountWritten */
  624.     return(SUCCESS);
  625. }
  626.  
  627. /*
  628.  *----------------------------------------------------------------------
  629.  *
  630.  * ServeIOControl --
  631.  *
  632.  *    Handle an IOControl.  This acts like an echo now.
  633.  *
  634.  * Results:
  635.  *    SUCCESS
  636.  *
  637.  * Side effects:
  638.  *    Copies the request buffer to the reply buffer.
  639.  *
  640.  *----------------------------------------------------------------------
  641.  */
  642.  
  643. ReturnStatus
  644. ServeIOControl(streamID, requestPtr, requestBuf, replyBuf, selectBitsPtr)
  645.     int streamID;
  646.     Pdev_Request *requestPtr;
  647.     Address requestBuf;
  648.     Address replyBuf;
  649.     int *selectBitsPtr;
  650. {
  651. #ifdef notdef
  652.     if (requestPtr->hdr.replySize <= requestPtr->requestSize) {
  653.     bcopy(requestBuf, replyBuf, requestPtr->hdr.replySize);
  654.     } else {
  655.     bcopy(requestBuf, replyBuf, requestPtr->requestSize);
  656.     bzero(replyBuf[requestPtr->requestSize],
  657.         requestPtr->hdr.replySize - requestPtr->requestSize);
  658.     }
  659. #endif
  660.     switch (requestPtr->param.ioctl.command) {
  661.     case IOC_PDEV_SET_BUF: {
  662.         /*
  663.          * Let the client trigger our test of the mid-flight
  664.          * setbuf call.
  665.          */
  666.         Pdev_SetBufArgs setBuf;
  667.  
  668.         setBuf.requestBufAddr = malloc(requestBufSize);
  669.         setBuf.requestBufSize = requestBufSize;
  670.         setBuf.readBufAddr = (Address)NULL;
  671.         setBuf.readBufSize = 0;
  672.         Fs_IOControl(streamID, IOC_PDEV_SET_BUF,
  673.                 sizeof(Pdev_SetBufArgs), (Address)&setBuf, 0, NULL);
  674.     
  675.     }
  676.     }
  677.     *selectBitsPtr = FS_WRITABLE;
  678.     if (! selectP) {
  679.     *selectBitsPtr |= FS_READABLE;
  680.     }
  681.     return(SUCCESS);
  682. }
  683. @
  684.  
  685.  
  686. 1.3
  687. log
  688. @Updated to new, standard, pseudo-device interface
  689. @
  690. text
  691. @d13 1
  692. a13 1
  693. static char rcsid[] = "$Header: server.c,v 1.2 88/08/26 16:23:53 brent Exp $ SPRITE (Berkeley)";
  694. d19 1
  695. d22 1
  696. a22 1
  697. #include "io.h"
  698. d26 1
  699. d28 1
  700. a28 1
  701. char *pdev="./pdev.new";
  702. d32 1
  703. d43 1
  704. a43 1
  705.     int *selectMask;
  706. a47 1
  707. #define REQUEST_BUF_SIZE    (2048 + sizeof(Pdev_Request))
  708. d55 1
  709. a55 1
  710. extern Boolean select;
  711. d106 4
  712. a109 4
  713.     statePtr = (ServerState *)Mem_Alloc(sizeof(ServerState));
  714.     statePtr->clientStream = (int *)Mem_Alloc(numClients * sizeof(int));
  715.     statePtr->clientState = (char *)Mem_Alloc(numClients);
  716.     statePtr->request = (Address *)Mem_Alloc(numClients * sizeof(Address));
  717. d116 1
  718. d122 4
  719. a125 11
  720.     status = Fs_Open(pdev, FS_READ|FS_CREATE|FS_NEW_MASTER,
  721.              0666, &statePtr->cntlStream);
  722. #ifdef notdef
  723.     if (status == FS_FILE_NOT_FOUND) {
  724.     status = Fs_Open(pdev, FS_CREATE|FS_READ|FS_NEW_MASTER,
  725.              0666, &statePtr->cntlStream);
  726.     }
  727. #endif 
  728.     if (status != SUCCESS) {
  729.     Stat_PrintMsg(status, "Error opening pseudo device as master");
  730.     Proc_Exit(status);
  731. d131 2
  732. a132 2
  733.      * that contain new streamIDs.  These are for private streams
  734.      * back to the client process..
  735. d134 5
  736. a138 6
  737.     len = sizeof(notify);
  738.     status = Fs_Read(statePtr->cntlStream, len, (Address)¬ify,
  739.                          &amountRead);
  740.     if (status != SUCCESS) {
  741.         Stat_PrintMsg(status, "Error reading control stream");
  742.         Proc_Exit(status);
  743. d140 1
  744. a140 1
  745.         Io_PrintStream(io_StdErr,
  746. a141 1
  747.         Io_Flush(io_StdErr);
  748. d150 2
  749. a151 1
  750.     statePtr->request[client] = Mem_Alloc(REQUEST_BUF_SIZE);
  751. d153 1
  752. a153 1
  753.     setBuf.requestBufSize = REQUEST_BUF_SIZE;
  754. d165 1
  755. a165 2
  756.     Io_PrintStream(io_StdErr, "Got client on stream %d\n",streamID);
  757.     Io_Flush(io_StdErr);
  758. a169 1
  759.     Io_Flush(io_StdErr);
  760. d175 2
  761. a176 2
  762.     statePtr->selectMask = (int *)Mem_Alloc(statePtr->selectMaskBytes);
  763.     Byte_Zero(statePtr->selectMaskBytes, (Address)statePtr->selectMask);
  764. d178 1
  765. a178 1
  766.     Bit_Set(statePtr->clientStream[client], statePtr->selectMask);
  767. d208 5
  768. a214 2
  769.     Pdev_Reply reply;
  770.     Pdev_BufPtrs bufPtrs;
  771. a216 1
  772.     char replyBuf[REQUEST_BUF_SIZE];
  773. d225 4
  774. a228 6
  775.     status = Fs_Read(clientStreamID, sizeof(Pdev_BufPtrs),
  776.         (Address) &bufPtrs, &numBytes);
  777.     if ((status != SUCCESS) || (numBytes != sizeof(Pdev_BufPtrs))) {
  778.     Sys_Panic(SYS_FATAL, "%s; status \"%s\", count %d",
  779.         "ServeRequest had trouble reading request buffer pointers",
  780.         Stat_GetMsg(status), numBytes);
  781. d231 1
  782. a231 2
  783.     Sys_Panic(SYS_FATAL, "%s: %d",
  784.         "ServeRequest got bad pointer magic number",
  785. d233 4
  786. d244 7
  787. a250 3
  788.     if (requestPtr->magic != PDEV_REQUEST_MAGIC) {
  789.         Sys_Panic(SYS_FATAL, "ServeRequest, bad request magic # 0x%x\n",
  790.                 requestPtr->magic);
  791. d254 8
  792. d265 1
  793. a265 1
  794.     operation = requestPtr->operation;
  795. d273 1
  796. a273 1
  797.     if (!writeBehind || operation != PDEV_WRITE) {
  798. d280 1
  799. a280 1
  800.         reply.replySize = requestPtr->replySize;
  801. d282 2
  802. d288 1
  803. a288 1
  804.         Sys_Panic(SYS_FATAL, "%s; status \"%s\"",
  805. d293 1
  806. a293 1
  807.     bufPtrs.requestFirstByte += requestPtr->messageSize;
  808. d325 1
  809. a325 1
  810.     int *selectMask;
  811. d331 1
  812. a331 1
  813.     selectMask = (int *)Mem_Alloc(statePtr->selectMaskBytes);
  814. d334 3
  815. a336 3
  816.     Byte_Copy(statePtr->selectMaskBytes, (Address)statePtr->selectMask,
  817.                          (Address)selectMask);
  818.     status = Fs_Select(statePtr->numClients, NULL, selectMask,
  819. d343 1
  820. a343 1
  821.         if (Bit_IsSet(statePtr->clientStream[client], selectMask)) {
  822. d354 1
  823. a354 1
  824.             Io_PrintStream(io_StdErr, "Client %d %s...", client,
  825. a355 1
  826.             Io_Flush(io_StdErr);
  827. d359 2
  828. a360 2
  829.                 statePtr->selectMask);
  830.         } else if ((operation == PDEV_READ) && select) {
  831. d374 1
  832. a374 1
  833.             Io_Print("Waking up client\n"); Io_Flush(io_StdOut);
  834. d383 1
  835. a383 2
  836.     Io_PrintStream(io_StdErr, "\n");
  837.     Io_Flush(io_StdErr);
  838. d410 1
  839. a410 1
  840.     int *selectMask;
  841. d423 1
  842. a423 1
  843.         Io_PrintStream(io_StdErr, "Client %d %s...", client,
  844. a424 1
  845.         Io_Flush(io_StdErr);
  846. d426 1
  847. a426 1
  848.     } else if ((operation == PDEV_READ) && select) {
  849. d440 1
  850. a440 1
  851.         Io_Print("Waking up client\n"); Io_Flush(io_StdOut);
  852. d447 1
  853. a447 2
  854.     Io_PrintStream(io_StdErr, "\n");
  855.     Io_Flush(io_StdErr);
  856. d474 2
  857. a475 2
  858.     if (requestPtr->replySize > 0) {
  859.     Byte_Zero(requestPtr->replySize, replyBuf);
  860. d505 1
  861. a505 2
  862.     Io_PrintStream(io_StdErr, "Open request, streamID %d\n", streamID);
  863.     Io_Flush(io_StdErr);
  864. d536 1
  865. a536 1
  866.     if (select && !blocked) {
  867. d541 2
  868. a542 2
  869.     if (requestPtr->replySize > 0) {
  870.         Byte_Zero(requestPtr->replySize, replyBuf);
  871. d546 1
  872. a546 1
  873.     if (! select) {
  874. d580 1
  875. a580 1
  876.     if (! select) {
  877. d583 2
  878. a584 1
  879.     requestPtr->replySize = 0;
  880. d613 2
  881. a614 2
  882.     if (requestPtr->replySize <= requestPtr->requestSize) {
  883.     Byte_Copy(requestPtr->replySize, requestBuf, replyBuf);
  884. d616 3
  885. a618 3
  886.     Byte_Copy(requestPtr->requestSize, requestBuf, replyBuf);
  887.     Byte_Zero(requestPtr->replySize - requestPtr->requestSize,
  888.             replyBuf[requestPtr->requestSize]);
  889. d629 2
  890. a630 2
  891.         setBuf.requestBufAddr = Mem_Alloc(REQUEST_BUF_SIZE);
  892.         setBuf.requestBufSize = REQUEST_BUF_SIZE;
  893. d639 1
  894. a639 1
  895.     if (! select) {
  896. @
  897.  
  898.  
  899. 1.2
  900. log
  901. @Increased buffer size, added delay
  902. @
  903. text
  904. @d13 1
  905. a13 1
  906. static char rcsid[] = "$Header: server.c,v 1.1 88/04/16 12:28:31 brent Exp $ SPRITE (Berkeley)";
  907. d45 1
  908. a45 1
  909. #define REQUEST_BUF_SIZE    (2048 + sizeof(Pdev_NewRequest))
  910. a54 1
  911. Pdev_WaitInfo waitInfo;
  912. d210 1
  913. a210 1
  914. ServeRequest(clientStreamID, requestBuf, opTable)
  915. d212 1
  916. a212 1
  917.     Address requestBuf;
  918. d216 2
  919. a217 2
  920.     register Pdev_NewRequest *requestPtr;
  921.     Pdev_NewReply reply;
  922. d247 1
  923. a247 1
  924.     requestPtr = (Pdev_NewRequest *)&requestBuf[bufPtrs.requestFirstByte];
  925. d252 1
  926. a252 1
  927.     requestData = (Address)((int)requestPtr + sizeof(Pdev_NewRequest));
  928. d275 1
  929. a275 1
  930.                     sizeof(Pdev_NewReply),
  931. d463 1
  932. a463 1
  933.     Pdev_NewRequest *requestPtr;
  934. d494 1
  935. a494 1
  936.     Pdev_NewRequest *requestPtr;
  937. d499 1
  938. a499 2
  939.     Io_PrintStream(io_StdErr, "Open request, streamID %d, clientID %d\n",
  940.         streamID, requestPtr->param.open.clientID);
  941. d526 1
  942. a526 1
  943.     Pdev_NewRequest *requestPtr;
  944. d569 1
  945. a569 1
  946.     Pdev_NewRequest *requestPtr;
  947. d601 1
  948. a601 1
  949.     Pdev_NewRequest *requestPtr;
  950. @
  951.  
  952.  
  953. 1.1
  954. log
  955. @Initial revision
  956. @
  957. text
  958. @d13 1
  959. a13 1
  960. static char rcsid[] = "$Header: server.c,v 1.3 87/06/12 15:03:41 brent Exp $ SPRITE (Berkeley)";
  961. d29 1
  962. d45 1
  963. a45 1
  964. #define REQUEST_BUF_SIZE    2048
  965. d225 1
  966. d261 4
  967. @
  968.